home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Helpers / Tzu Release 4 / Tool Development / TzuTextUtils.cp < prev    next >
Encoding:
Text File  |  1994-10-15  |  1.3 KB  |  49 lines  |  [TEXT/MMCC]

  1. // 
  2. // TextUtilities
  3. // ©1994 Chris K. Thomas.  All Rights Reserved.
  4. //
  5. // These will probably be incorporated as
  6. // TzuTool utiltity callbacks.
  7. //
  8. // InsertText written Oct 12 or 13 94 <ckt>
  9. // DeleteText written Oct 13 or 14 94 <ckt>
  10.  
  11. #include "TzuTextUtils.h"
  12. #include <Memory.h>
  13.  
  14. pascal void InsertText(Handle hText,long insertOffset,long insertLen,const void *insert)
  15. {
  16.     long    hTextLen    = GetHandleSize(hText);
  17.     char    hTextState    = HGetState(hText);
  18.     Ptr        localText    = NULL;
  19.     
  20.     // SetHandleSize might need to move the memory to resize it
  21.     // which it can't do if the handle is locked
  22.     HUnlock(hText);
  23.     SetHandleSize(hText,hTextLen + insertLen);
  24.     if(MemError()!=noErr) return;
  25.     
  26.     HLockHi(hText);
  27.     localText = *hText;
  28.     
  29.     BlockMoveData(&localText[insertOffset],&localText[insertOffset+insertLen],hTextLen - insertOffset);
  30.     BlockMoveData(insert,&localText[insertOffset],insertLen);
  31.     
  32.     HSetState(hText,hTextState);
  33. }
  34.  
  35. pascal void DeleteText(Handle hText,long offsetToText,long textLen)
  36. {
  37.     long    hTextLen    = GetHandleSize(hText);
  38.     char    hTextState    = HGetState(hText);
  39.     Ptr        localText    = NULL;
  40.     
  41.     localText = *hText;
  42.     
  43.     BlockMoveData(&localText[offsetToText+textLen],&localText[offsetToText],hTextLen - (offsetToText+textLen));    
  44.     HUnlock(hText);
  45.     SetHandleSize(hText,hTextLen - textLen);
  46.     HLockHi(hText);
  47.     
  48.     HSetState(hText,hTextState);
  49. }